package Utils;

import GUI.MainFrame;

import javax.swing.*;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

import static java.awt.Image.SCALE_DEFAULT;


/**
 * The type ImageIcon utils.
 *
 * @author dzr
 * @version 1.0
 */
public class ImageIconUtils {

    /**
     * Get profile image icon.
     *
     * @param id     the id
     * @param width  the width
     * @param height the height
     * @return the image icon
     */
    public static ImageIcon getProfile(int id, int width, int height){
        URL headerUrl = ImageIcon.class.getResource("/profiles/" + id + ".png");
        String iconPath = headerUrl.getPath();
        try {
            iconPath = URLDecoder.decode(iconPath, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ImageIcon icon = new ImageIcon(headerUrl);
        icon = new ImageIcon(icon.getImage().getScaledInstance(width, height, SCALE_DEFAULT));
        return icon;
    }

    /**
     * Get RawPicture as icon.
     *
     * @param name    the picture name
     * @return the image icon
     */
    public static ImageIcon getRawPicture(String name){
        URL headerUrl = ImageIcon.class.getResource("/rawPicture/" + name);
        String iconPath = headerUrl.getPath();
        try {
            iconPath = URLDecoder.decode(iconPath, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ImageIcon icon = new ImageIcon(headerUrl);
        icon = new ImageIcon(icon.getImage());
        return icon;
    }
}
